<template>
	<view>
		<view class="name">
			{{item.name}}
			你到这里有{{dis}}km
			<button type="default" @tap="goto">到这里去</button>
			<uni-fav :checked="hasFav" @click="onclickFav"></uni-fav>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,computed
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		CONFIG
	} from '../../utils/config';
	import {
		userStore
	} from '../../store/userStore';
	
	import {getMapDistance} from "@/utils/tools.js"
	let store = userStore()
	// 景点
	let item=ref({})
	let dis =ref()
	
	onLoad((data)=>{
		getItemById(data.id)
	})
	async  function getItemById(id)
	{
		let data = {
			"objectId": id
		}
		let ed = encodeURI(JSON.stringify(data))
		let res = await uni.$get(CONFIG.leancloud_url + "/1.1/classes/xianplayitem?where=" + ed)
		console.log(res)
		item.value=res.results[0]
		console.log(item.value)
		uni.setNavigationBarTitle({
			title:item.value.name
		})
		console.log(store.currentPos)
		console.log(item.value.lat,item.value.lon)
		dis.value=getMapDistance(store.currentPos.latitude,store.currentPos.longitude,
		item.value.lat,item.value.lon
		)
	}
	 
	 function  goto(){
		 uni.navigateTo({
		 	url:`/pages/mywebView/mywebView?lat=${item.value.lat}&lon=${item.value.lon}&name=${item.value.name}`
			// url:"../mywebView/mywebView"
		 })
	 }
	 
	 const hasFav=ref(true)
		 
	 function onclickFav(){
		 hasFav.value=!hasFav.value
	 }
</script>

<style>

</style>
